import server from '@/utils/http';
import qs from 'qs';
import { PaginationQuery } from '@/types/table';

enum Api {
    materialTypeListCommon = '/api/material/getMaterialTypeListCommon',
    getMaterialByType = '/api/material/getMaterialByType',
    addMaterialType = '/api/material/addMaterialType',
    getMaterialTypeList = '/api/material/getMaterialTypeList',
    deleteMaterialByIds = '/api/material/deleteMaterialByIds',
    deleteTypeByTypeCode = '/api/material/deleteTypeByTypeCode',
    addTag = '/api/material/addTag',
    deleteTag = '/api/material/deleteTag',
    upMaterial = '/api/material/uploadImg',
    addMaterial = '/api/material/addMaterial',
    moveMaterial = '/api/material/moveMaterial',
}

/**
 * @description 根据商户编码 和 素材大类标识（可选）返回素材大类及类型--> 商户端-门店端 --> 平台素材-我的素材
 * @param
 * @param page 页码
 * @param size pageSize
 * @sort 排序方式 默认level,asc
 * @return { content: 列表, totalElements： 总数 }
 */
export const postMaterial = (query: any): Promise<TableResponse> => {
    return server.Post(Api.materialTypeListCommon, query);
};

/**
 * @description 根据商户编码 和 素材大类标识（可选）返回素材大类及类型--> 商户端-门店端 --> 平台素材-我的素材
 * @param
 * @param page 页码
 * @param size pageSize
 * @sort 排序方式 默认level,asc
 * @return { content: 列表, totalElements： 总数 }
 */
export const postMaterialByType = (query: any): Promise<TableResponse> => {
    return server.Post(Api.getMaterialByType, query);
};

/**
 * @description 查询平台端分类
 * @param

 * @return { content: 列表, totalElements： 总数 }
 */
export const getMaterialTypeList = (materialClass: any): Promise<TableResponse> => {
    return server.Get(Api.getMaterialTypeList + `?materialClass=${materialClass}`);
};

/**
 * @description 新增分类
 * @param

 * @return 
 */
export const addMaterialType = (query: any): Promise<void> => {
    return server.Post(Api.addMaterialType, query);
};
/**
 * @description 删除分类
 * @param

 * @return 
 */
export const deleteMaterialByIds = (ids: any): Promise<void> => {
    console.log(ids);
    return server.Delete(Api.deleteMaterialByIds, ids);
};

/**
 * @description 删除素材分类
 * @param

 * @return 
 */
export const deleteTypeByTypeCode = (picTypeCode: any): Promise<void> => {
    return server.Get(Api.deleteTypeByTypeCode + `?picTypeCode=${picTypeCode}`);
};

/**
 * @description 新增类型
 * @param

 * @return 
 */
export const postAddTag = (query: any): Promise<void> => {
    return server.Post(Api.addTag, query);
};

/**
 * @description 删除类型
 * @param

 * @return 
 */
export const postDelTag = (query: any): Promise<void> => {
    return server.Post(Api.deleteTag, query);
};

export const postUpMaterial = (params: NormalObj): Promise<any> => {
    return server.Post(Api.upMaterial, params, { headers: { 'Content-Type': 'multipart/form-data' } });
};

/**
 * @description 新增素材
 * @param

 * @return 
 */
export const addMaterial = (query: any): Promise<void> => {
    return server.Post(Api.addMaterial, query);
};

/**
 * @description 移动素材
 * @param

 * @return 
 */
export const moveMaterial = (query: any): Promise<void> => {
    return server.Post(Api.moveMaterial, query);
};
